﻿#!/usr/bin/python

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class MainWindow(QDialog):
    def __init__(self):
        super(MainWindow, self).__init__()
        
        self.i = 0
        
        vbox = QVBoxLayout() #水平布局管理器
        hbox = QHBoxLayout() #垂直布局管理器
        
        self.threadAButton = QPushButton('Start A')
        self.threadBButton = QPushButton('Start B')
        self.quitButton    = QPushButton('Quit')
        
        self.textBrowser = QTextBrowser()
        
        vbox.addWidget(self.threadAButton)
        vbox.addWidget(self.threadBButton)
        vbox.addWidget(self.quitButton)
        
        hbox.addWidget(self.textBrowser)
        hbox.addLayout(vbox)
        
        self.setLayout(hbox)
        
        t1 = Thread(12)
        t2 = Thread(30)
        
        t1.signal.connect(self.updateUi)
        t1.start()
        
    def updateUi(self, i):
        # self.i = self.i+1
        self.textBrowser.append(str(i))
        
class Thread(QThread):
    signal = pyqtSignal(int)
    def __init__(self, i):
        super(Thread, self).__init__()
        self.i = i;
    def run(self):
        for item in range(5):
            self.i = self.i + 1
            self.signal.emit(self.i)
            sleep(0.1)
        
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainwindow = MainWindow()
    mainwindow.show()
    sys.exit(app.exec_())